package test.ui {
	import gear.core.Game;
	import gear.net.AssetData;
	import gear.net.LibData;
	import gear.net.RESManager;
	import gear.net.SWFLoader;
	import gear.ui.containers.GPanel;
	import gear.ui.controls.GAlert;
	import gear.ui.controls.GButton;
	import gear.ui.controls.GCheckBox;
	import gear.ui.controls.GRadioButton;
	import gear.ui.controls.GTab;
	import gear.ui.controls.GTextInput;
	import gear.ui.controls.GToggleButton;
	import gear.ui.data.GAlertData;
	import gear.ui.data.GButtonData;
	import gear.ui.data.GCheckBoxData;
	import gear.ui.data.GPanelData;
	import gear.ui.data.GRadioButtonData;
	import gear.ui.data.GTabData;
	import gear.ui.data.GTextInputData;
	import gear.ui.data.GToggleButtonData;
	import gear.ui.group.GToggleGroup;
	import gear.ui.layout.GLayout;
	import gear.ui.manager.UIManager;

	import flash.events.Event;
	import flash.events.MouseEvent;

	/**
	 * @version 20091215
	 * @author bright
	 */
	[SWF(width=1000,height=570,backgroundColor=0x333333,frameRate=30)]
	public class TestGroup extends Game {
		private var _alert : GAlert;

		override protected function startup() : void {
			RESManager.instance.add(new SWFLoader(new LibData("assets/ui.swf")));
			RESManager.instance.addEventListener(Event.COMPLETE, completeHandler);
			RESManager.instance.load();
		}

		private function completeHandler(event : Event) : void {
			addRadioGroup();
			addCheckBox();
			addTBGroup();
			addButtons();
			addTextInput();
			addTabGroup();
			addAlert();
		}

		private function addAlert() : void {
			var data : GAlertData = new GAlertData();
			data.labelData.text = "你好啊!";
			data.flag = GAlert.OK | GAlert.CANCEL;
			data.parent = UIManager.root;
			_alert = new GAlert(data);
		}

		private function addTextInput() : void {
			var data : GTextInputData = new GTextInputData();
			data.x = 180;
			data.y = 30;
			addChild(new GTextInput(data));
		}

		private function addCheckBox() : void {
			var data : GCheckBoxData = new GCheckBoxData();
			data.x = 180;
			data.y = 10;
			data.labelData.text = "检查按钮";
			addChild(new GCheckBox(data));
		}

		private function addButtons() : void {
			var data : GButtonData = new GButtonData();
			data.x = 300;
			data.y = 30;
			data.height = 24;
			data.labelData.text = "开始游戏";
			var start_btn : GButton = new GButton(data);
			start_btn.enabled = false;
			addChild(start_btn);
			start_btn.addEventListener(MouseEvent.CLICK, start_clickHandler);
		}

		private function start_clickHandler(event : MouseEvent) : void {
			_alert.show();
			GLayout.layout(_alert);
		}

		private function addRadioGroup() : void {
			var data : GRadioButtonData = new GRadioButtonData();
			data.parent = this;
			data.x = 10;
			data.y = 10;
			data.labelData.text = "我是谁?";
			var rb1 : GRadioButton = new GRadioButton(data);
			data = data.clone();
			data.x = 80;
			data.labelData.text = "他是谁";
			var rb2 : GRadioButton = new GRadioButton(data);
			addChild(rb1);
			addChild(rb2);
			var group : GToggleGroup = new GToggleGroup();
			group.model.add(rb1);
			group.model.add(rb2);
		}

		private function addTBGroup() : void {
			var data : GToggleButtonData = new GToggleButtonData();
			data.x = 10;
			data.y = 40;
			data.labelData.text = "hello";
			var tb1 : GToggleButton = new GToggleButton(data);
			addChild(tb1);
		}

		private function addTabGroup() : void {
			var panelData : GPanelData = new GPanelData();
			panelData.bgSkin = UIManager.getSkin(new AssetData("GTabPanel_bgSkin"));
			panelData.x = 10;
			panelData.y = 101;
			panelData.width = 200;
			panelData.height = 120;
			var panel : GPanel = new GPanel(panelData);
			addChild(panel);
			var data : GTabData = new GTabData();
			data.x = 10;
			data.y = 80;
			data.width = 55;
			data.labelData.text = "选项1";
			var tab1 : GTab = new GTab(data);
			data.x = 64;
			data = data.clone();
			data.labelData.text = "选项2";
			var tab2 : GTab = new GTab(data);
			data = data.clone();
			data.x = 118;
			data.labelData.text = "选项3";
			var tab3 : GTab = new GTab(data);
			addChild(tab1);
			addChild(tab2);
			addChild(tab3);
			var group : GToggleGroup = new GToggleGroup();
			group.model.add(tab1);
			group.model.add(tab2);
			group.model.add(tab3);
		}

		public function TestGroup() {
			super();
		}
	}
}
